package com.zmn.plat.admin.controller.service.itempart;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.dubbo.utils.DubboConsts;
import com.zmn.plat.model.entity.service.itempart.ItemPart;
import com.zmn.plat.model.entity.service.itempart.ItemPartQuery;
import com.zmn.plat.services.interfaces.service.itempart.ItemPartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;


/**
 * 项目-关联配件基础查询Controller
 *
 * @author guoqiao
 * @since 2021/11/19 19:07
 */
@Slf4j
@RestController
@RequestMapping("/service/itempart")
public class ItemPartListController extends ServiceItemPartBaseController {

    private ItemPartService itemPartService;

    /**
     * 描述: 查询列表
     *
     * @author guoqiao
     * @since 2021/11/19 19:07
     */
    @RequestMapping("/list")
    public ModelAndView list(ItemPartQuery query) {

        List<ItemPart> items = itemPartService.listPageByQuery(query);

        ModelAndView mv = new ModelAndView("service/itempart/list");
        mv.addObject("items", items);
        mv.addObject("vo", query);

        return mv;
    }

    /**
     * 描述: 详情
     *
     * @author guoqiao
     * @since 2021/11/19 19:07
     */
    @RequestMapping("/addEditView")
    public ModelAndView addEditView(@RequestParam(value = "relateId") Integer relateId) {

        ItemPart itemPart;
        if (NumberUtil.isNullOrZero(relateId)) {
            itemPart = new ItemPart();
        } else {
            itemPart =  itemPartService.findById(relateId);
        }
        ModelAndView mv = new ModelAndView("service/itempart/detail");
        mv.addObject("itemPart", itemPart);

        return mv;
    }

}
